<template>
	<view>
		<view class="turn_money_box">
			<image src="../../static/bizhan/yellow_red.png" mode="aspectFill" class="yellow_red"></image>
			<view class="f28 c999 from_to">
				<view>从</view>
				<view>到</view>
			</view>
			<view class="account_box">
				<view class="ore_account set_pad">
					<view class="accoun_name f30 cfff">{{type?'USDT账户':'SMK收益'}}</view>
					<view class="coin f30 c666"> {{ type? Uname:name}}</view>
				</view>
				<view class="wallet_account set_pad">
					<view class="accoun_name f30 cfff">{{!type?'USDT账户':'SMK账户'}}</view>
					<view class="coin f30 c666">{{ !type? Uname:name}}</view>
				</view>
			</view>
			<view @tap="changeType()">
				<image src="../../static/bizhan/up.png" mode="aspectFill" class="up_img"></image>
				<image src="../../static/bizhan/down.png" mode="aspectFill" class="down_img"></image>
			</view>
			
		</view>
		<view class="title f30 cfff">
			数量
		</view>
		<view class="input_box">
			<input type="text" style="color: #fff;" v-model="money" placeholder="请输入划转数量"/>
			<view class="all_turn f30" @tap="allmoney">
				全部划转
			</view>
		</view>
		<view class="tips f24 c999">
			最多可转 {{(type?poolAccount:earnings) | toTwo(4)}} SMK
		</view>
		<view class="determine_box" @tap="showPay=true">
			确认划转
		</view>
		<alert alertTitle="提示" alertText="确认划转吗"  v-if="showPay" @alertConfirm='alertConfirm'></alert>
	</view>
</template>

<script>
	import md5 from '@/common/md5.min.js'
	import alert from '@/components/alert/alert.vue'
	export default {
		data() {
			return {
				name:'',
				Uname:'',
				type:false, //true USDT账户 false 平台币账户 1.usdt划转SMK   2.SMK划转usdt
				poolAccount:0, //矿池余额
				earnings:0 ,//钱包余额
				money:'',
				showPay:false
			}
		},
		components:{alert},
		onLoad(e) {
			this.name=e.name
		this.Uname=e.Uname
			this.poolAccount=e.poolAccount
			this.earnings=e.earnings
		},
		onNavigationBarButtonTap (e){
			console.log(e)
			if( e.text == "钱包明细" ){
				this.$open('../user/wallet_pay')
			}else if(e.text == "刷新"){
					window.location.reload()
			}
		
		},
		methods: {
			alertConfirm(type,payPassword){
				if(this.money<=0){
					this.$sToast('划转金额错误')
					this.showPay=false
					return
				}
				if(type==1){
					this.type?this.toAccount(payPassword):this.toPool(payPassword)
				}
				this.showPay=false
			},
			// 矿池账户->钱包账户划转
			toAccount(payPassword){
				this.$ajax('/bi/conversionSMKUSDT',{
					userId:uni.getStorageSync('userinfo').userId,
					money:this.money,
					type:1
				},"POST").then(res => {
					this.$sToast('划转成功')
					this.$back(1,1500)
				});
			},
			// 钱包账户->矿池账户划转
			toPool(payPassword){
				this.$ajax('/bi/conversionSMKUSDT',{
					userId:uni.getStorageSync('userinfo').userId,
					money:this.money,
					type:2
				},"POST").then(res => {
					this.$sToast('划转成功')
					this.$back(1,1500)
				});
			},
			changeType(){
				this.type=!this.type
			},
			allmoney(){
				this.money=(this.type?this.poolAccount:this.earnings)
			}
		}
	}
</script>

<style>
	page{
		padding-left: 30rpx;
		background-color: #0E1B45;
	}
.turn_money_box{
	width:690rpx;
	height:265rpx;
	background:rgba(255,255,255,1);
	box-shadow:0rpx 0rpx 16rpx 0rpx rgba(2,151,254,0.1);
	border-radius:12rpx;
	display: flex;
	flex-direction: row;
	align-items: center;
	background-color: #3F4D63;
}
.from_to{
	display: flex;
	flex-direction: column;
	height: 157rpx;
	justify-content: space-between;
}
.yellow_red{
	width: 18rpx;
	height: 144rpx;
	margin: 0 30rpx 0 20rpx;
}
.up_img,.down_img{
	width: 14rpx;
	height: 42rpx;
	margin-right: 4rpx;
}
.account_box{
	width: 460rpx;
	margin: 0 29rpx 0 42rpx;
}
.accoun_name{
	margin-bottom: 13rpx;
}
.ore_account{
	border-bottom: 1rpx solid #F3F3F3;
}
.f30{
	line-height: 30rpx;
}
.title{
	margin-top: 67rpx;
}
.set_pad{
	padding: 30rpx 0 30rpx 0;
}
.input_box{
	display: flex;
	flex-direction: row;
	border-bottom: 1rpx solid #E0E0E0;
	justify-content: space-between;
	padding:26rpx 30rpx 30rpx 0;
}
.determine_box{
	width:690rpx;
	height:85rpx;
	background:#00B34D;
	border-radius:8rpx;
	text-align: center;
	font-size: 30rpx;
	line-height: 85rpx;
	color: #FFFFFF;
}
.all_turn{
	border-left: 1rpx solid #E0E0E0;
	padding-left: 29rpx;
	color: #0297FE;
	line-height: 40rpx;
}
.tips{
	margin: 19rpx 0 50rpx 0;
}
</style>
